package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    cnt := make(map[string]int)
    files := os.Args[1:]
    if len(files) == 0 {
        count(os.Stdin, cnt)
    } else {
        for _, args := range files {
            f, err := os.Open(args)
            if err != nil {
                fmt.Fprintf(os.Stderr, "dup2 %v\n", err)
                continue
            }

            count(f, cnt)
            f.Close()
        }
    }

    for i, j := range cnt {
        if j > 1 {
            fmt.Printf("%s\t%d\n", i, j)
        }
    }
}

func count(f *os.File, cnt map[string]int) {
    input := bufio.NewScanner(f)
    for input.Scan() {
        cnt[input.Text()]++
    }
}
